package com.alks.entity.data.response;

import com.alks.entity.data.enums.ResultCodeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

/**
 * @author:xxxxx
 * @create: 2023-06-15 11:13
 * @Description:
 */
@Getter
@Setter
@NoArgsConstructor
@ToString
public class ResponseInfo<T> {
    @ApiModelProperty("数据")
    private T data;
    @ApiModelProperty("信息")
    private String message;
    @ApiModelProperty("响应")
    private Integer code;
    public static <T> ResponseInfo<T> ok(T data){
        ResponseInfo responseInfo = new ResponseInfo();
        responseInfo.setCode(ResultCodeEnum.SUCCESS.getCode());
        responseInfo.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        responseInfo.setData(data);
        return responseInfo;
    }

    public static <T> ResponseInfo<T> ok(String msg){
        ResponseInfo responseInfo = new ResponseInfo();
        responseInfo.setCode(ResultCodeEnum.SUCCESS.getCode());
        responseInfo.setMessage(msg);
        return responseInfo;
    }

    public static <T> ResponseInfo<T> fileLoading(){
        ResponseInfo responseInfo = new ResponseInfo();
        responseInfo.setCode(ResultCodeEnum.FILE_GENERATE.getCode());
        responseInfo.setMessage(ResultCodeEnum.FILE_GENERATE.getMessage());
        return responseInfo;
    }

    public static <T> ResponseInfo<T> error(String msg,Integer code){
        ResponseInfo responseInfo = new ResponseInfo();
        responseInfo.setCode(code);
        responseInfo.setMessage(msg);
        return responseInfo;
    }

    public static <T> ResponseInfo<T> error(String msg){
        ResponseInfo responseInfo = new ResponseInfo();
        responseInfo.setCode(504);
        responseInfo.setMessage(msg);
        return responseInfo;
    }
    public static <T> ResponseInfo<T> ok(){
        ResponseInfo responseInfo = new ResponseInfo();
        responseInfo.setCode(ResultCodeEnum.SUCCESS.getCode());
        responseInfo.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        responseInfo.setData(null);
        return responseInfo;
    }
    public static <T> ResponseInfo<T> ok(T data,String message){
        ResponseInfo responseInfo = new ResponseInfo();
        responseInfo.setCode(ResultCodeEnum.SUCCESS.getCode());
        responseInfo.setMessage(message);
        responseInfo.setData(data);
        return responseInfo;
    }

    public static <T> ResponseInfo<T> warn(String msg){
        ResponseInfo responseInfo = new ResponseInfo();
        responseInfo.setCode(301);
        responseInfo.setMessage(msg);
        return responseInfo;
    }

    public static <T> ResponseInfo<T> retry(String msg){
        ResponseInfo responseInfo = new ResponseInfo();
        responseInfo.setCode(202);
        responseInfo.setMessage(msg);
        return responseInfo;
    }

    public static <T> ResponseInfo<T> warn(String msg,T data){
        ResponseInfo responseInfo = new ResponseInfo();
        responseInfo.setData(data);
        responseInfo.setMessage(msg);
        return responseInfo;
    }
}
